package com.ftg.learn.exam.sys.mapper;

import org.apache.ibatis.jdbc.SQL;

/**
 * @author KangJx
 * @date 2021/4/27
 */
public class SysSql {

    /**
     * 这是用于生成相应的分页带模糊功能
     * @param page   页码
     * @param limit  显示几条
     * @param rolename  角色名称
     * @param isdelete  状态
     * @return
     */
    public String rolePage(int page, int limit,String rolename,int isdelete){
        return new SQL(){{
            SELECT("id,role_name,role_desc,is_deleted");
            FROM("exam_sys_role");
            if(rolename != null && !rolename.equals("")){
                WHERE("role_name like concat(#{param3},'%')");
            }
            WHERE("is_deleted = #{param4}");

            LIMIT("#{param1},#{param2}");//开始
            ORDER_BY("create_time");
        }}.toString();
    }

    /**
     * 统计模糊查询共有多少条
     * @param rolename
     * @param isdelete
     * @return
     */
    public String countPageRole(String rolename,int isdelete){
        return new SQL(){{
            SELECT("count(id)");
            FROM("exam_sys_role");
            if(rolename != null && !rolename.equals("")){
                WHERE("role_name like concat(#{param1},'%')");
            }
            WHERE("is_deleted = #{param2}");
        }}.toString();
    }

}
